package auth

import (
	"context"
	"github.com/pkg/errors"
	log "github.com/sirupsen/logrus"
	"twwch/k8s-admin/application/base"
	"twwch/k8s-admin/common/jwtAuth"
	"twwch/k8s-admin/models/auth"
)

type AuthService struct {
	base.BaseService
}

var svc = &AuthService{}

func GetService() *AuthService {
	svc.Logger = log.WithField("service", "auth")
	return svc
}

func (svc *AuthService) Token(ctx context.Context, req *auth.TokenReq) (*auth.TokenResp, error) {
	if req.UserId != "XgZP9Ky1TqcfnlNsfdsfsfsfp6cdghjdsgfsjdamCgBkPrcXTUaM" {
		return nil, errors.New("pass error")
	}
	token, err := jwtAuth.Setting(req.UserId)
	if err != nil {
		svc.Logger.Error(ctx, err)
		return nil, err
	}
	resp := &auth.TokenResp{
		Token: token,
	}
	return resp, nil
}
